package com.yj.idempotence.dynamicDataSource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicDataSource extends AbstractRoutingDataSource {


    private final static ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<>();


    @Override
    protected Object determineCurrentLookupKey() {
        return THREAD_LOCAL.get();
    }

    public static void setThreadLocal(String dataSourceName){
        THREAD_LOCAL.set(dataSourceName);
    }

    public String getThreadLocal(){
        return THREAD_LOCAL.get();
    }

    public static void removeThreadLocal(){
        THREAD_LOCAL.remove();
    }

}
